/*
 *    Copyright 2010-2013 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.google.code.jbauble.db;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.google.code.jbauble.db.exception.DataAccessException;

/**
 * sql操作对象
 * @author Drizzt
 *
 */
public interface SqlNative {
	/** 得到数据连接 */
	Connection getConnection(int type) throws DataAccessException;
	
	/** 查询并返回列表 */
	<T> List<T> queryForList(String sql, Object[] objs, final Class<T> type) throws DataAccessException;

	/** 查询并返回单个对象 */
	<T> T queryForObject(String sql, Object[] objs, final Class<T> type) throws DataAccessException;
	
	/** 查询并返回数字 */
	Long queryForLong(String sql, Object[] objs) throws DataAccessException;
	
	/** 执行sql */
	int execute(String sql, Object[] objs) throws DataAccessException;
	
	/** 执行sql，并返回自增主键 */
	Object executeInsert(final String sql, final Object[] objs) throws DataAccessException;
	
	/** 开始事务 */
	SqlTransaction beginTransaction() throws DataAccessException;
}
